/*
 ============================================================================
 文件名 	: CEasyBounceDataReader.cpp
 描述		: CEasyBounceDataReader类的实现.
 ============================================================================
 */

//引用
#include <f32file.h> 
#include <utf.h>
#include <COEMAIN.H>
#include "EasyBounceRankDataReader.h"

_LIT( KFileName, "c:\\ebrank.txt");

// ============================ 成员函数 ===============================

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::~CEasyBounceDataReader()
// 析构函数.
// -----------------------------------------------------------------------------
//
CEasyBounceDataReader::~CEasyBounceDataReader()
	{
	Cancel();
	iRankDataFile.Close();
	delete iRawRankData;
	iRawRankData = NULL;
	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::NewLC()
// 两阶段构造函数.
// -----------------------------------------------------------------------------
//
CEasyBounceDataReader* CEasyBounceDataReader::NewLC()
	{
	CEasyBounceDataReader* self = new (ELeave) CEasyBounceDataReader();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::NewL()
// 两阶段构造函数.
// -----------------------------------------------------------------------------
//
CEasyBounceDataReader* CEasyBounceDataReader::NewL()
	{
	CEasyBounceDataReader* self = CEasyBounceDataReader::NewLC();
	CleanupStack::Pop(self);
	return self;
	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::ReadDataL()
// 使用活动对象读取文件里的数据
// -----------------------------------------------------------------------------
//
void CEasyBounceDataReader::ReadDataL()
	{
	User::LeaveIfError(iRankDataFile.Open(iFs, KFileName, EFileRead));
	iRankDataFile.Read(*iRawRankData, iStatus);
	SetActive();
	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::CEasyBounceDataReader()
// 析构函数.
// -----------------------------------------------------------------------------
//
CEasyBounceDataReader::CEasyBounceDataReader() : CActive (EPriorityStandard)
	{
	CActiveScheduler::Add(this);
	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::ConstructL()
// 两阶段构造函数.
// -----------------------------------------------------------------------------
//
void CEasyBounceDataReader::ConstructL()
	{
	//TODO: initialize file session
	iFs = CCoeEnv::Static()->FsSession();
	iRawRankData = new TBuf8<KMaxLength>;
	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::RunL()
// 异步操作完成后由活动对象规划器调用
// -----------------------------------------------------------------------------
//
void CEasyBounceDataReader::RunL()
	{
	if( iStatus != KErrNone )
		{
		User::Leave(KErrGeneral);
		}
	
	//TODO:update ranklist
	//TODO:redraw listbox

	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::DoCancel()
// 析构时由CActive::Cancel()方法调用
// -----------------------------------------------------------------------------
//
void CEasyBounceDataReader::DoCancel()
	{
	iRankDataFile.ReadCancel(iStatus);
	iRankDataFile.Close();
	}

// -----------------------------------------------------------------------------
// CEasyBounceDataReader::DoCancel()
// RunL()中发生Leave时，由活动对象规划器调用此函数
// -----------------------------------------------------------------------------
//
TInt CEasyBounceDataReader::RunError()
	{
	User::Leave(KErrGeneral);
	}

//文件结束
//iRankContainer->RankList()->UpdateRankData(iRawRankData);
//iRankContainer->ListBox()->DrawNow();
//delete iRankData;
//iRankData = NULL;
